package com.test.configure;

import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author : caili
 * @date : 16:54 2023/1/14
 */
@Configuration
public class RabbitMqConfig {
    /**
     * 工作模式下 消费者参数配置
     * 不同监听队列可配置不同参数 通过@RabbitListener(containerFactory = "beanName")注入
     * @param configurer
     * @param connectionFactory
     * @return
     */
    @Bean("workContainerFactory")
    public SimpleRabbitListenerContainerFactory containerFactory(SimpleRabbitListenerContainerFactoryConfigurer configurer,
                                                                 ConnectionFactory connectionFactory) {
        SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
        //并发数量:根据实际的服务器性能进行配置即可
        factory.setConcurrentConsumers(4);
        factory.setMaxConcurrentConsumers(6);
        factory.setPrefetchCount(10);
        configurer.configure(factory, connectionFactory);
        return factory;
    }
}
